<?php

require_once("classes/adrese.template.class.php");


$lid = $_GET["id"];
$new = $_GET["new"];
$ret = $_GET["ret"];

if(!isset($lid) && !$new){
	die("No address id.");
}elseif($new){
	$lid = NULL;
}


// instantinate class
// param: int sifra_adrese
$ul_template = new adrese_template($lid);


if($new){
	// define html-object names (inputs, selects)
	$field_names = array(
	// naziv u tpl		=> naziv na strani
		"new_region"	=> "region",
		"new_opstina"	=> "opstina",
		"new_grad"		=> "grad",
		"new_lokopstina"=> "lok_opstina",
		"new_naselje"	=> "naselje",
		"new_ulica"		=> "ulica",
		"new_broj"		=> "broj"
	);
	$ul_template->defineFieldNames($field_names);
	
	$ul_template->addNew();
	if($ret){
		return $ul_template->template_html;
	}else{
		echo $ul_template->template_html;
	}
}else{
	// define html-object names (inputs, selects)
	// ulica i broj
	$ul_template->defineFieldNames(array("txt_ulica"=>"ulica","txt_broj"=>"broj"));
	// naselje
	$ul_template->defineFieldNames(array("select_naselje"=>"naselje"));
	// lok.opstina
	$ul_template->defineFieldNames(array("select_lokopstina"=>"lokalna_opstina"));
	// grad
	$ul_template->defineFieldNames(array("select_grad"=>"grad"));
	// opstina
	$ul_template->defineFieldNames(array("select_opstina"=>"opstina"));
	// region
	$ul_template->defineFieldNames(array("select_region"=>"region"));
	
	
	
	// parse desired type of template
	// param: string type
	// 	ulica i broj  => "ulica" 
	// 	naselje	 => "naselje"
	// 	lok.opst.	 => "lok_opstina"
	// 	grad	 => "grad"
	// 	opstina	 => "opstina"
	// 	region	 => "region"
	//	all	 => NULL
	$ul_template->parseIt($_GET["t"]);
		
	if($ret){
		return $ul_template->template_html;
	}else{
		echo $ul_template->template_html;
	}
}
?>